package com.ruoyi.web.controller.system;


import com.ruoyi.system.domain.ClassificationNode;
import com.ruoyi.system.domain.dto.*;
import com.ruoyi.system.service.impl.SysClassificationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/api/classification")
@Slf4j
public class SysClassificationController {

    @Autowired
    SysClassificationService sysClassificationService;

    @PostMapping("/getNode")
    public ResponseEntity<?> getNode(
            @RequestBody IdRequest request
    ) {

        Map<String,String> answer = sysClassificationService.getNode(request.getId());
        return ResponseEntity.ok(answer);
    }

    @PostMapping("/getNodeInfo")
    public ResponseEntity<?> getNodeInfo(
            @RequestBody IdRequest request
    ){
        Map<String,String> answer = sysClassificationService.getNodeInformation(request.getId());
        return ResponseEntity.ok(answer);
    }

    @PostMapping("/getNodeAttr")
    public ResponseEntity<?> getNodeAttr(
            @RequestBody AttrRequest request
    ){
        Map<String,String> answer = sysClassificationService.getAttribute(request.getId(),request.getPageSize(),request.getCurPage());
        return ResponseEntity.ok(answer);
    }

    @PostMapping("/createNode")
    public ResponseEntity<?> createNode(
            @RequestBody ClassificationNode request
    ){
        Map<String,String> answer = sysClassificationService.createTypeNode(request);
        return ResponseEntity.ok(answer);
    }

    @PostMapping("/addNodeAttr")
    public ResponseEntity<?> addNodeAttr(
            @RequestBody AddAttrRequest request
    ){
        String answer = sysClassificationService.addNodeAttr(request.getId(),request.getAttrIdArray());
        return ResponseEntity.ok(answer);
    }

    @PostMapping("/deleteNodeAttr")
    public ResponseEntity<?> deleteNodeAttr(
            @RequestBody DeleteAttrRequest request
    ){
        String answer = sysClassificationService.deleteNodeAttr(request.getAttrIdArray());
        return ResponseEntity.ok(answer);
    }

    @PostMapping("/deleteNode")
    public ResponseEntity<?> deleteNode(
            @RequestBody IdRequest request
    ){
        String answer = sysClassificationService.deleteTypeNode(request.getId());
        return ResponseEntity.ok(answer);
    }

    @PostMapping("/searchByName")
    public ResponseEntity<?> searchByName(
          @RequestBody ClassificationNode request
    ){

        Map<String,String> answer = sysClassificationService.searchByName(request);
        return ResponseEntity.ok(answer);

    }

    @PostMapping("/searchByBusinessCode")
    public ResponseEntity<?> searchByBusinessCode(
            @RequestBody BusinessCodeRequest request
    ){
        Map<String,String> answer = sysClassificationService.serchByBusinessCode(request.getBusinessCode());
        return ResponseEntity.ok(answer);
    }
}
